<?php

class ml_tool_pinOutput
{
    /**
     * 生成PIN HTML
     *
     *
     * @param array $pin_data
     * 单条记录规则
     * array(
     *        'uid' =>
     *        'nick' =>
     *        'rid' =>
     *        'pic_id' =>
     *        'content' =>
     *        'like_cnt' =>
     *        'cmt_cnt' =>
     *        'quote_cnt' =>
     *        'ctime' =>    // yyyy-mm-dd HH:ii:ss
     *        'is_attitude'    => //true/false
     *        'attitude_score'    => //int
     *        'is_quote' => //
     *     'quote_info' = array()
     * )
     * @return unknown
     */
    static public function parsePinboardTpl($pin_data , $canDel = true)
    {
        $currentTime = $_SERVER['REQUEST_TIME'];

        foreach ($pin_data as $data)
        {
            
            $data['time'] = ml_tool_standardShow::time($data['ctime'],true);//pin的时间格式
            $data['price'] = ml_tool_standardShow::rmb_price($data['gd_price']);
                
            $data['content'] = ml_tool_formatContent::format_content($data['content']);
                
            $data['title'] = Tool_string::un_html($data['gd_title']);
            $data['nick'] = Tool_string::un_html($data['nick']);
            $data['portrait'] = ml_tool_picid::uid2portrait($data['uid'] , 'atm');
            $data['picurl']=ml_tool_picid::pid2url($data['pic_id'],ml_tool_picid::IMGSIZE_PIN);//
            //$data['height']=
            $data['is_goods'] = Tool_dataMultiplex::isAttribute($data['type_xrank'] , ML_CONTENT_XRANK_GOODS);
            $data['canDel'] = $canDel;
            $data['quote_cnt'] = $data['quote_cnt'] ? $data['quote_cnt'] : 0;
            $data['cmt_cnt'] = $data['cmt_cnt'] ? $data['cmt_cnt'] : 0;
            $data['like_cnt'] = $data['like_cnt'] ? $data['like_cnt'] : 0;
            $data['img_height'] = ml_tool_picid::pid2h($data['pic_id']);

            $controller = ml_factory::get_controller();
            $data['visitor'] = $controller->get_visitor();
            if($data['is_quote']){
                $data['quote_info']['content'] = ml_tool_formatContent::format_content($data['quote_info']['content']);
                $data['portrait'] = ml_tool_picid::uid2portrait($data['quote_info']['uid'] , 'tny');
            }
            //$data['is_quote']=false;//我相信，他们还会改回去的，所以只是临时方法
            $aHtml[] = ml_tool_template::parseModTpl($data , 'pin');
        } 
       
        
        return $aHtml;
    }
    
    public function groupPinByColumn($aHtml ,$colCnt = 4, $block_col = array())
    {
        
        $block_cnt = 0;
        $aMatrix = array_pad(array() , $colCnt , array());
        foreach ($block_col as $k => $v)
        {
            $block_cnt += $v;
            $aMatrix[$k] = array_pad(array() , $v , '');
        }
        
        $total = count($aHtml) + $block_cnt;
        
        for ($i = 0;$i<$total ; $i++)
        {
            $colN = $i % $colCnt;
            $rowN = floor($i/$colCnt);
            
            if($aMatrix[$colN][$rowN] !== '')
            {
                $aMatrix[$colN][$rowN] = array_shift($aHtml);
            }
        }    
        return $aMatrix;
        
    }
}